#!/bin/sh
workcodedir='/root/.jenkins/workspace/demo'
workdir='/root/.jenkins/workspace/run'
filename='demo-0.0.1-SNAPSHOT.jar'
suffix=$(date "+%Y%m%d%H%M%S")
# -x 参数判断 $folder 是否存在并且是否具有可执行权限
cd /
if [ ! -d workcodedir ]
then
  sudo -S mkdir -p $workcodedir
else
  echo 'code目录有了'
fi

if [ ! -d $workdir ]
then
  sudo -S mkdir -p $workdir
else
  echo 'run目录有了'
fi

cd $workdir ||return
git pull
mvn clean
mvn package
cp workdir/$filename workdir/$filename$suffix.bak
rm -f workdir/$filename
pid=$(ps -ef | grep 'java -jar' | grep -v grep | awk '{print $2}')
str="杀进程-pid ${pid}"
echo $str
kill -9 $pid
cp $filename workdir/$filename
cd workdir/$filename
nohup java -jar $filename &





